﻿using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;

using System;
using System.Collections.Generic;
using System.Linq;

namespace ExprParser
{
  public variant PExpr
  {
    | BinOperator     { LeftExpr : PExpr; Op : string; RightExpr : PExpr; }
    | PrefixOperator  { Op : string; Expr : PExpr; }
    | PostfixOperator { Op : string; Expr : PExpr; }
    | Ident           { Name : string; }
    | Num             { Value : int; }
    | If              { Cond : PExpr; Expr1 : PExpr; Expr2 : PExpr; }
    | Error           { Msg : string; }

    public override ToString() : string
    {
      match (this)
      {
        | BinOperator    (leftExpr, op, rightExpr) => $"$op($leftExpr, $rightExpr)"
        | If             (cond, e1, e2)            => $"o:if($cond, $e1, $e2)"
        | PrefixOperator (op, expr)                => $"p:$op($expr)"
        | PostfixOperator(op, expr)                => $"s:$op($expr)"
        | Ident          (name)                    => $"$name"
        | Num            (value)                   => $"$value"
        | Error          (msg)                     => $"'Error: $msg'"
      }
    }
  }
}
